<template>
  <div class="autumn-container">
    <!-- 面包 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/dashboard' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>区划列表</el-breadcrumb-item>
    </el-breadcrumb>

    <div class="autumn-center">
      <!-- 搜索栏 -->
      <div class="query-form">
        <autumn-search :modelValue="queryInfo" @search="search">
          <template #default>
            <el-form-item prop="code" label="关键词">
              <el-input v-model="queryInfo.code" placeholder="代码/名称/拼音" />
            </el-form-item>
          </template>
        </autumn-search>
      </div>

      <!-- 数据表格 -->
      <div class="main-body top">
        <autumn-table :page="page" @changePage="changePage">
          <template #column>
            <el-table-column type="index" label="#" fixed="left" align="center">
              <template #default="scope">
                {{ initIndex(scope.$index) }}
              </template>
            </el-table-column>
            <el-table-column prop="code" label="代码" />
            <el-table-column prop="name" label="名称" />
            <el-table-column prop="deep" label="行政等级" align="center" width="80" />
            <el-table-column prop="zipCode" label="邮编" align="center" width="100" />
            <el-table-column prop="cityCode" label="城市区号" align="center" width="100" />
            <el-table-column prop="mergerName" label="组合名称" />
            <el-table-column prop="pinyin" label="拼音" />
            <el-table-column prop="longitude" label="经度" align="center" width="100" />
            <el-table-column prop="latitude" label="纬度" align="center" width="100" />
          </template>
        </autumn-table>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from 'vue'
import { pageProvince } from 'src/api/system/province'
import useTable from 'src/hooks/useTable'

const { page, initIndex } = useTable()

const queryInfo = reactive({
  code: ''
})
const changePage = (pageNumber: number, pageSize: number) => {
  page.pageNumber = pageNumber
  page.pageSize = pageSize
  pageProvince({ ...queryInfo, pageNumber, pageSize }).then(({ data }) => {
    page.data = data.list
    page.total = data.total
  })
}
const search = () => {
  changePage(1, 10)
}
search()
</script>

<style lang="scss" scoped>
</style>
